﻿using B.S.BaseData.Api.Read.Command.GoodsCommand;
using B.S.BaseData.ErrorCode;
using B.S.BaseData.Infrastructure.Interface;
using B.S.BataBase.Domain.Entitys;
using MediatR;

namespace B.S.BaseData.Api.Read.CommandHandler.GoodsCommandHandler
{
    public class GoodsslaughterShowCommandHandler : IRequestHandler<GoodsslaughterShowCommand, APIResult<GoodsslaughterInfo>>
    {
        private readonly IBaseRepository<GoodsslaughterInfo> _slaughterbaseRepository;
        public GoodsslaughterShowCommandHandler(IBaseRepository<GoodsslaughterInfo> slaughterbaseRepository)
        {
            _slaughterbaseRepository = slaughterbaseRepository;
        }
        public async Task<APIResult<GoodsslaughterInfo>> Handle(GoodsslaughterShowCommand request, CancellationToken cancellationToken)
        {
            APIResult<GoodsslaughterInfo> result = new APIResult<GoodsslaughterInfo>();
            try
            {
                var list = await _slaughterbaseRepository.GetValues(x => x.GoodsId == request.Id);
                result.Data = list;
                result.Msg = "屠宰信息显示成功";
                result.Code = ApiEnum.Success;
                return await Task.FromResult(result);
            }
            catch (Exception)
            {
                result.Msg = "屠宰信息显示失败";
                result.Code = ApiEnum.Fail;
                return await Task.FromResult(result);
            }
        }
    }
}
